import React, {useEffect} from 'react';
import {useAppDispatch} from "@/hooks";
import {getFindByParentIdAsync, useSelectorDict} from "@/store/slice/dict";
import {Table} from "antd";

function Dict() {
    const dispatch = useAppDispatch();
    const {dictList,loading} = useSelectorDict()
    useEffect(()=>{
        dispatch(getFindByParentIdAsync(1))
    },[])
    return (
        <div>
            <Table
                loading={loading}
                columns={[
                    {
                        title:"名称", // 表格的标头
                        dataIndex:"name"//会将dataSource数组中元素(对象)
                    },{
                        title:"编码", // 编码
                        dataIndex:"dictCode"//
                    },{
                        title:"值", //
                        dataIndex:"value"//会将dataSource数组中元素(对象)
                    },{
                        title:"创建时间", // 表格的标头
                        dataIndex:"createTime"//会将dataSource数组中元素(对象)
                    }
                ]}
                //不显示分页
                pagination={false}
                //唯一标识
                rowKey={"id"}
                //数据数组
                dataSource={dictList}
                //配置展开属性
                expandable= {{
                    onExpand(expanded,record){
                        if(expanded){
                            dispatch(getFindByParentIdAsync(record.id))
                        }
                    }
                }}
            >
            </Table>
        </div>
    );
}

export default Dict;